﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace CYP.IISMonitor.Utility.Mails
{
    /// <summary>
    /// 邮件管理
    /// </summary>
    public static class MailManager
    {
        /// <summary>
        /// 异常邮件发送方法
        /// </summary>
        /// <param name="platformId">平台id</param>
        /// <param name="errorMsg">要发送的邮件信息</param>
        public static void SendErrorMailClient(string platformId, string errorMsg)
        {
            ////获取平台设置
            //Platform pSettings = WcfConfigManager.ClientEx.Platforms[platformId];
            ////邮件发送给
            //string strMail = pSettings.MailTo;
            //if (string.IsNullOrEmpty(strMail))
            //{
            //    return;
            //}

            ////邮件标题
            //string strSubject = pSettings.Subject;
            ////邮件内容
            //string strBody = pSettings.MailBody;
            ////WCF显示名
            //string strWcfDisplayName = pSettings.WcfDisplayName;
            //if (string.IsNullOrEmpty(strWcfDisplayName))
            //{
            //    strWcfDisplayName = string.Empty;
            //}
            ////各系统的显示名
            //string strDisplayName = pSettings.DisplayName;
            ////实例化邮件发送对象
            //SendMail sendMail = SendMail.GetInstance("dispute");
            ////邮件发件人显示名
            //sendMail.DisplayName = pSettings.SenderName;
            ////异步发送邮件
            //sendMail.SendAsyncHtml(strSubject, strMail, string.Format(strBody, strDisplayName, errorMsg, strWcfDisplayName));
        }

        /// <summary>
        /// 异常邮件发送方法
        /// </summary>
        /// <param name="errorMsg">要发送的邮件信息</param>
        public static void Send(string msg)
        {
            //发邮件设置
            string mailTo = ConfigHelper.GetConfig("MailTo");
            string mailSubject = ConfigHelper.GetConfig("MailSubject");
            string mailDisplayName = ConfigHelper.GetConfig("MailSenderDisplayName");
            string mailInstance = ConfigHelper.GetConfig("MailSenderInstance");
            string mailBody = ConfigHelper.GetConfig("MailBody");

            if (string.IsNullOrEmpty(mailTo))
            {
                return;
            }

            //实例化邮件发送对象
            SendMail sendMail = SendMail.GetInstance(mailInstance);
            //设置显示的发件人的名字
            sendMail.DisplayName = mailDisplayName;
            //异步发送邮件
            sendMail.SendAsyncHtml(mailSubject, mailTo, String.Format("{0}    {1}.", mailBody, msg));
        }
    }
}
